package com.yimi.yinhepda.entity.response;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 000432
 * @date 2017/4/17 0017
 *
 * 差异扫描的返回
 */

public class DifferScanResponse {

  private List<DifferScanEntity> data;
  private boolean success;
  private String[] errorMessages;
  private int errorCode;

  public List<DifferScanEntity> getData() {
    return data;
  }

  public void setData(List<DifferScanEntity> data) {
    this.data = data;
  }

  public boolean isSuccess() {
    return success;
  }

  public void setSuccess(boolean success) {
    this.success = success;
  }

  public String[] getErrorMessages() {
    return errorMessages;
  }

  public void setErrorMessages(String[] errorMessages) {
    this.errorMessages = errorMessages;
  }

  public int getErrorCode() {
    return errorCode;
  }

  public void setErrorCode(int errorCode) {
    this.errorCode = errorCode;
  }

  /**
   * 总票数
   */
  public int getTotalPiao() {
    if (data == null) {
      return 0;
    }
    return data.size();
  }

  /**
   * 总件数
   */
  public int getTotalJian() {
    if (data == null || data.size() <= 0) {
      return 0;
    }
    int count = 0;
    for (DifferScanEntity entity : data) {
      count += entity.getStocktakingDiffreportInventoryVoList().size();
    }
    return count;
  }

  /**
   * 总已扫描票数
   */
  public static int getTotalScannedPiao(List<DifferScanEntity> data) {
    if (data == null || data.size() <= 0) {
      return 0;
    }
    int count = 0;
    List<DifferChild> childList;
    for (DifferScanEntity item : data) {
      childList = item.getStocktakingDiffreportInventoryVoList();
      for (DifferChild childItem : childList) {
        if (childItem.getStatus() == 1) {
          count++;
          break;//加一次就好，退出当前for循环，继续
        }
      }
    }
    return count;
  }

  /**
   * 总已经扫描件数
   */
  public static int getTotalScannedJian(List<DifferScanEntity> data) {
    if (data == null || data.size() <= 0) {
      return 0;
    }
    int count = 0;
    for (DifferScanEntity entity : data) {
      count += entity.getScannedNum();
    }
    return count;
  }

  public static class DifferScanEntity implements Comparable<DifferScanEntity> {
    /** 运单号 */
    private String waybillNo;
    /** 包装 */
    private String packingSpecification;
    /** 少货件数 */
    private Integer lessNum;
    /** 处理件数 */
    private Integer dealtNum;
    private List<DifferChild> stocktakingDiffreportInventoryVoList;

    public List<DifferChild> getStocktakingDiffreportInventoryVoList() {
      if (stocktakingDiffreportInventoryVoList == null || stocktakingDiffreportInventoryVoList.size() <= 0) {
        stocktakingDiffreportInventoryVoList = new ArrayList<>();
      }
      return stocktakingDiffreportInventoryVoList;
    }

    public void setStocktakingDiffreportInventoryVoList(List<DifferChild> stocktakingDiffreportInventoryVoList) {
      this.stocktakingDiffreportInventoryVoList = stocktakingDiffreportInventoryVoList;
    }

    public String getWaybillNo() {
      return waybillNo;
    }

    public void setWaybillNo(String waybillNo) {
      this.waybillNo = waybillNo;
    }

    public String getPackingSpecification() {
      return packingSpecification;
    }

    public void setPackingSpecification(String packingSpecification) {
      this.packingSpecification = packingSpecification;
    }

    public Integer getLessNum() {
      if (lessNum == null) {
        lessNum = 0;
      }
      return lessNum;
    }

    public void setLessNum(Integer lessNum) {
      this.lessNum = lessNum;
    }

    public Integer getDealtNum() {
      if (dealtNum == null) {
        dealtNum = 0;
      }
      return dealtNum;
    }

    public void setDealtNum(Integer dealtNum) {
      this.dealtNum = dealtNum;
    }

    /***
     * 运单中已经扫描的
     */
    /**
     * 获取已经扫描的子单数量
     */
    public int getScannedNum() {
      int count = 0;
      if (stocktakingDiffreportInventoryVoList == null) {
        return 0;
      }
      for (DifferChild childInfo : stocktakingDiffreportInventoryVoList) {
        if (childInfo.getStatus() != null && childInfo.getStatus() == 1) {
          count++;
        }
      }
      return count;
    }

    /**
     * 颜色
     */
    public int getColorInt() {
      //开单数量
      int lessNum = getLessNum();
      //扫描数量
      int scannedNum = getScannedNum();
      if (scannedNum == 0) {
        //白色
        return 1;
      } else if (scannedNum < lessNum) {
        //红色
        return 0;
      }
      if (scannedNum > lessNum) {
        //黄色
        return 2;
      } else {
        //绿色
        return 3;
      }
    }

    @Override public int compareTo(DifferScanEntity differScanEntity) {
      return this.getColorInt() - differScanEntity.getColorInt();
    }
  }

  public static class DifferChild {
    /** 子单号或者包号 */
    private String waybillChildNo;
    /** 0是未扫描，1是已扫描 */
    private Integer status;

    public String getWaybillChildNo() {
      return waybillChildNo;
    }

    public void setWaybillChildNo(String waybillChildNo) {
      this.waybillChildNo = waybillChildNo;
    }

    public Integer getStatus() {
      if (status == null) {
        status = 0;
      }
      return status;
    }

    public void setStatus(Integer status) {
      this.status = status;
    }
  }
}
